package com.fen.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.api.R;
import com.fen.common.Result;
import com.fen.common.StringConsts;
import com.fen.dao.UserMapper;
import com.fen.pojo.User;
import com.fen.service.UserService;
import com.fen.service.lmpl.UserServicelmpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description: springbootsc
 * @Author: lijiafen
 * @Date: 2021/12/15
 * @Time: 14:56
 * @eamil: 2368044269@qq.com
 */
@RestController
public class UserController {

    @Autowired
    UserServicelmpl service;

    @Autowired
    UserMapper mapper;
    /**
    * @Description: 注销用户
    * @Author: lijiafen
    */
    @RequestMapping("/deleteUser")
   public Result deleteUser(String phone)
   {
       if (StringUtils.checkValNull(phone))
       {
           return Result.getFailure().setDate("请输入电话号码");
       }
       QueryWrapper<User>queryWrapper=new QueryWrapper<>();
       queryWrapper.eq("phone",phone);
       User user = mapper.selectOne(queryWrapper);
       if (user==null)
       {
           return Result.getFailure().setDate(StringConsts.USER_NOT_EXIST);
       }
       int i = mapper.delete(queryWrapper);
       if (i>0)
       {
           return Result.getSuccess().setDate(StringConsts.LOGINOUT_SUCCESS);
       }else {
           return Result.getFailure().setDate(StringConsts.LOGINOUT_FALL);
       }
   }
}
